<?php
/*
  Template Name: show_product_single
 */
?>

<?php
if (isset($_GET["pid"]) && !empty($_GET["pid"])) {
    $pid = $_GET["pid"];
    require_once( get_template_directory() . '/model/product-model.php' );
    $query = " SELECT * FROM  `ys_product` WHERE id='" . $pid . "'";
    $data = ProductModel::selectProduct($query, "ARRAY_A", 0, CommonModel::SELECT_TYPE_ROW);
    voteProduct($data['id']);
    if ($data == False)
        return;
}else {
    return;
}
?>  




<style>
    .table{background:None;}
    .table ul{float:left;margin:0px;padding:0px;}
    .table ul li{list-style:none;padding:4px 33px;}
    .table ul li.title{font-weight:bold;background:#333;color:#fff;}
    .table ul li.even{background:#fff;}
    .table ul li.odd{background:#FFFFE6;}
    .col-list-vert{float: left; width:100px; }
    .ui-square-small{
        display: block;
        float: left;
        width: 4px;
        height: 4px;
        margin-right: 0.4em;
        margin-top: 0.6em;
        background-color: #124560;
    }
</style>

<div class="content">
    <div class="content_botbg">
        <div class="content_res">

            <div id="breadcrumb">
<?php //if (function_exists('cp_breadcrumb')) cp_breadcrumb(); ?>

            </div>
            <div class="clr"></div>

            <div class="content_left">

                <?php appthemes_stats_update($post->ID); //records the page hit  ?>

                <div class="shadowblock_out <?php cp_display_style('featured'); ?>">

                    <div class="shadowblock">

                        <h1 class="single-listing"><?php echo $data["name"]; ?></a></h1>

                        <div class="clr"></div>

                        <p class="post-meta">
                            <span class="folder">
                                <a href="#" rel="tag">
                                    <?php
                                    //category
                                    $category_ad_id = $data['category_id'];
                                    $category = get_term($category_ad_id, 'category', $output, $filter);
                                    echo $category->name;

                                    $user_id = $data['user_id'];
                                    $user = get_userdata($user_id);
                                    $username = $user->user_nicename;
                                    ?>


                                </a>

                            </span> | <span class="owner">
                                <a href="<?php echo get_site_url() . "?author=" . $data["user_id"]; ?>" title="Tạo bởi <?php echo $username; ?>" rel="author"><?php echo $username; ?></a>
                            </span> | <span class="clock">
                                <span>
                                    <?php
                                    $time_created = $data['time_created'];
                                    echo ys_humanTiming($time_created);
                                    ?>
                                </span>

                            </span>
                        </p>

                        <div class="pad5 dotted"></div>

                        <div class="bigright table">
                            <ul>
                                <?php if (!empty($data["code"]) && $data["code"]!=""){ ?>
                                <li class="titile">
                                    <i class="ui-square-small"></i>
                                    <span class="col-list-vert">Mã số"</span> <?php echo $data["code"];?>
                                </li>
                                <?php } ?>
                                
                                <?php if (!empty($data["source"]) && $data["source"]!=""){ ?>
                                <li class="odd">
                                    <i class="ui-square-small"></i>
                                    <span class="col-list-vert">Xuất xứ:</span><?php echo $data["source"];?>
                                </li>
                                <?php } ?>
                                
                                <?php if (!empty($data["amount"]) && $data["amount"]!=""){ ?>
                                <li class="odd">
                                    <i class="ui-square-small"></i>
                                    <span class="col-list-vert">Số lượng:</span><?php echo $data["amount"];?></li>
                                 <?php } ?>
                                
                                 <?php if (!empty($data["status"]) && $data["status"]!=""){ ?>
                                <li class="odd">
                                    <i class="ui-square-small"></i>
                                    <span class="col-list-vert">Tình trạng:</span>  
                                     <?php if (strcmp($data["status"],"new")==0){
                                        echo "Mới";
                                    }else{
                                        echo "Cũ";
                                    } ?>
                                </li>
                                  <?php } ?>
                            </ul>
                         
                        </div>


                            <?php if ($cp_options->ad_images) { ?>
                            <div class="bigleft">
                                <div id="main-pic">
                                 <?php //cp_get_image_url(); ?>
                                    <?php $stringIdPostAttachment = get_post_meta($data["id"], "product_attachment_image", True);
                                    $listIdPostAttachment = split(",", $stringIdPostAttachment);
                                    if (empty($stringIdPostAttachment) ||  $stringIdPostAttachment==""){
                                       
                                        $imageFor = "single_product_default";
                                        $defaultImage = getDefaultImage($imageFor);
                                        echo '<img style="width:100%; height:100%;" src="'.$defaultImage.'" class="attachment-medium" alt="">';
                                    }else
                                        echo wp_get_attachment_image( $listIdPostAttachment[0], "medium")
                                    ?>
                                    <div class="clr"></div>

                                </div>
                                 <div id="thumbs-pic">
                                <?php if(sizeof($listIdPostAttachment) >1)
                                    for($i=1; $i <sizeof($listIdPostAttachment) ; $i++){
                                    ?>
                                  <?php  echo wp_get_attachment_image( $listIdPostAttachment[$i], "thumbnail"); ?>
                                 
                                
                                <?php }?>
                                        <div class="clr"></div>

                                </div>

                            </div><!-- /bigleft -->

<?php } ?>

                        <div class="clr"></div>
                        <div class="single-main">

                            <?php
                            // 3.0+ display text areas in content area before content.
//                            cp_get_ad_details($post->ID, $cat_id, 'content');
                            if (!empty($data["description"]) && $data["description"]!= ""){
                            ?>

                            <h3 class="description-area">Mô tả</h3>

                            <?php
                            }
                            echo $data["description"];
                            ?>



                        </div>



                    </div><!-- /shadowblock -->

                </div><!-- /shadowblock_out -->



<?php appthemes_after_endwhile(); ?>



                <div class="clr"></div>

                <div class="clr"></div>

<?php comments_template('/comments-ad_listing.php'); ?>

            </div><!-- /content_left -->

<?php get_sidebar('ad'); ?>

            <div class="clr"></div>

        </div><!-- /content_res -->

    </div><!-- /content_botbg -->

</div><!-- /content -->
